<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ nickName }}</div>

    <!-- 图容器 -->
    <div class="chart-container">
      <div ref="pieChart" style="width: 100%; height: 400px;"></div>
    </div>

    <!-- 南丁格尔玫瑰图容器 -->
    <div class="chart-container">
      <div ref="roseChart" style="width: 100%; height: 400px;"></div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import * as echarts from 'echarts';


export default {
  name: 'View',
  data(){
    return{
      pieChartData: [
        { name: 'A', value: 30 },
        { name: 'B', value: 50 },
        { name: 'C', value: 70 },
        { name: 'D', value: 40 }
      ],
      roseChartData: [
        { name: 'X', value: 60 },
        { name: 'Y', value: 80 },
        { name: 'Z', value: 40 },
        { name: 'W', value: 90 }
      ]
    }
  },
  computed: {
    ...mapGetters(['name','nickName'])
  },
  components: {
    PieChart,
    RoseTypeChart,
    TooltipComponent,
    LegendComponent
  },
  methods: {
    initPieChart() {
      const chart = echarts.init(this.$refs.pieChart)
      const option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [{
          name: '数量',
          type: 'pie',
          radius: '50%',
          data: this.pieChartData,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }]
      }
      chart.setOption(option)
    },
    initRoseChart() {
      const chart = echarts.init(this.$refs.roseChart)
      const option = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [{
          name: '数量',
          type: 'pie',
          radius: ['20%', '70%'],
          center: ['50%', '55%'],
          roseType: 'radius',
          label: {
            show: false
          },
          data: this.roseChartData,
          itemStyle: {
            borderRadius: 5,
            borderColor: '#fff',
            borderWidth: 2
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }]
      }
      chart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
